﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Windows.Data;
using SoftSource.Common;
using SoftSource.Timecard.ViewModelInterfaces;
using SoftSource.Timecard.Web.Data;

namespace SoftSource.Timecard.ViewModels
{
    public sealed class ReportListViewModel : IReportListViewModel
    {
        #region IReportListViewModelConsume Members

        private PagedCollectionView reports;
        public PagedCollectionView Reports
        {
            get { return this.reports; }
            private set
            {
                this.reports = value;
                this.Reports.SortDescriptions.Add(new SortDescription(
                    ObjectReflection.GetPropertyName<Report>(r => r.ReportName),
                    ListSortDirection.Ascending));
                this.reports.MoveCurrentToFirst();
                this.PropertyChanged.Notify(() => this.Reports);
            }
        }

        public IObservable<Unit> Load { get; set; }

        #endregion

        #region IReportListViewModelService Members

        private IEnumerable<Report> reportCollection;
        public IEnumerable<Report> ReportCollection
        {
            get { return this.reportCollection; }
            set
            {
                this.reportCollection = value;
                this.Reports = new PagedCollectionView(this.reportCollection);
            }
        }

        #endregion
     
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        #endregion

        ~ReportListViewModel()
        {
            this.Dispose();
        }
    }
}
